<?php
class LayuiHtml{
	
	//***************************【layui 对应的JS输出函数】***********************************
	
	public static function lay_data_tr($data){
		return $data;
	}
	
	// 表单-开关
	public static function lay_switch_html($title,$name){
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
					<input type="checkbox" lay-skin="switch" value="'.$name.'" lay-text="启用|禁用" {if $model.'.$name.'??1 == 1} checked {/if}><input type="hidden" name="'.$name.'" value="{$model.'.$name.'??1}">
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表达-下拉菜单
	public static function lay_select_html($title,$name,$verify=''){
		
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
				  <select name="'.$name.'" '.$verify.'>
					<option value=""></option>
					{volist name="'.$name.'_option" id="v"}
					{if !$action_up}
					<option value="{$v.id}">{$v.name}</option>
					{elseif $v.id == $model.'.$name.'}
					<option value="{$v.id}" selected="selected">{$v.name}</option>
					{else/}
					<option value="{$v.id}">{$v.name}</option>
					{/if}
					{/volist}
				  </select>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
    
    // 搜索下拉菜单
    public static function lay_select_search_html($title,$name,$verify=''){
    	
    	$data='
    		<div class="layui-form-item">
    			<label class="layui-form-label">'.$title.'</label>
    			<div class="layui-input-block">
    			  <div id="'.$name.'_search"></div>
                  <input name="'.$name.'" type="hidden" value="{$model.'.$name.'??\'\'}"/>
    			</div>
    		</div>';
    	return self::lay_data_tr($data);
    }
	
	// 表单-复选框
	public static function lay_checkbox_html($title,$name){
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
					{volist name="'.$name.'" id="v"}
					{if in_array($v,$model.'.$name.'??[])}
					<input type="checkbox" name="'.$name.'[]" title="{$v}" value="{$v}" checked>
					{else/}
					<input type="checkbox" name="'.$name.'[]" title="{$v}" value="{$v}">
					{/if}
					{/volist}
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表单-单选框
	public static function lay_radio_html($title,$name){
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
					{php}if(!$action_up) $model["'.$name.'"]=0;{/php}
					{volist name="'.$name.'" id="v"}
					{if $v.id == $model.'.$name.'}
					<input type="radio" name="'.$name.'" title="{$v.val}" value="{$v.id}" checked>
					{else/}
					<input type="radio" name="'.$name.'" title="{$v.val}" value="{$v.id}">
					{/if}
					{/volist}
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表单样式文本
	public static function lay_text_html($title,$name,$verify=''){
        if($name=='sort'){
            $default='1000';
        }else{
            $default="''";
        }
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
				  <input type="text" name="'.$name.'" value="{$model.'.$name.'??'.$default.'}" placeholder="请输入'.$title.'" class="layui-input" '.$verify.'>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表单样式文本短
	public static function lay_text2_html($title,$name,$verify=''){
		$data='
			<div class="layui-form-item2 layui-col-md6">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
				  <input type="text" name="'.$name.'" value="{$model.'.$name.'??\'\'}" placeholder="请输入'.$title.'" class="layui-input" '.$verify.'>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表单文本域
	public static function lay_textarea_html($title,$name,$verify=''){
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
				  <textarea name="'.$name.'" placeholder="请输入'.$title.'" class="layui-textarea" '.$verify.'>{$model.'.$name.'??\'\'}</textarea>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 表单编辑器
	public static function lay_ueditor_html($title,$name,$verify=''){
		$data='
			<div class="layui-form-item">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
				  <textarea id="'.$name.'" name="'.$name.'" placeholder="请输入'.$title.'" class="layui-textarea" '.$verify.'>{$model.'.$name.'??\'\'}</textarea>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 图片选择
	public static function lay_photo_html($title,$name,$verify=''){
		$data='
			<div class="layui-form-item layui-img-upload">
				<label class="layui-form-label">'.$title.'</label>
				<div class="layui-input-block">
					{:opt_photo("'.$name.'")}
					<button class="pear-btn pear-btn-primary pear-btn-sm upload-image" type="button">
						<i class="icon pear-icon pear-icon-picture">
						</i>
						上传图片
					</button>
					<input name="'.$name.'" type="hidden" class="layui-input" value="{$model.'.$name.'??\'\'}">
					<div class="upload-image">
						<span>
						</span>
						<img class="upload-image" src="{$model.'.$name.'??\'\'}">
					</div>
				</div>
			</div>';
		return self::lay_data_tr($data);
	}
	
	// 图片选择多项
	public static function lay_photos_html($title,$name,$model,$empty=0,$long='',$verify=''){
		if(!isset($model[$name])){
			$model[$name]=[];
			//return $name.'该参数不存在，无法生成图片选项';
		}
		
		if(!is_array($model[$name])){
			return $name.'该参数不是数组，请使用lay_photo_html函数';
		}
		
		$images=$model[$name];
		if(count($images)<$empty){
			$images=[];
			for($j=0;$j<$empty;$j++){
				$images[$j]='';
			}
		}
		
		$data='';
		foreach($images as $key=>$value){
			$i=$key+1;
			$data.='
			<div class="';
			if($long==''){
				$data.='layui-form-item layui-img-upload';
			}else{
				$data.='layui-form-item2 layui-img-upload layui-col-md'.$long;
			}
			$data.='">
			    <label class="layui-form-label">'.$title.$i.'</label>
			    <div class="layui-input-block">
					<input name="'.$name.'['.$i.']" type="hidden" class="layui-input" value="'.$value.'" ';
			if ($verify!='') $data.='verify="'.$verify.'"';
			$data.='/>';
			
			$data.=opt_photo($name.$i);
			
			$data.='			
					<button class="pear-btn pear-btn-primary pear-btn-sm upload-image" type="button">
						<i class="icon pear-icon pear-icon-picture">
						</i>
						上传图片
					</button>
					<div class="upload-image">
						<span>
						</span>
						<img class="upload-image" src="'.$value.'"/>
					</div>
				</div>
			</div>';
		}
		
		return $data;
	}
	
}

?>